<!-- 
    Document   : simR
    Created on : 2008-5-26, 15:04:29
    Author     : hq
    bugfix: scrpt filename, png name
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>Simple R</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <!--<script src="cookie.js" language="JavaScript" type="text/javascript"></script>-->
    </head>
    <body>
        <!--   <script>
            today = new Date()
            var f=getCookie("N")
            if(f){
                addCookie("N",f);
            }else{
                f=Math.floor(Math.random()*100+1)+today.getTime()*100;
                addCookie("N",f);
            }
        </script>-->
        <h3>Run R script</h3>
        Input R script here:
        <form name="run" action=# method="POST">
            <textarea name="script" rows="6" cols="40"></textarea><BR>
            <input type="submit" value="Run" name="submit" />
        </form>
        <%
        setContentType("text/html")
        #filename <- COOKIES$"N"
        #picname <- paste(filename, ".png", sep="")
        #if(!is.null(POST$script)){
        script <- POST$script
        plotdir <- "/var/www/images/R" ###
        setwd(plotdir)
        if(!is.null(COOKIES$"N")){
        filename <- COOKIES$"N"
        }else{
        filename <- as.numeric(Sys.time())
        setCookie("N", filename)
        }
        file <- file.path("/tmp",paste(filename, ".R", sep=""))
        picname <- paste(filename, ".png", sep="")
        write(script, file=file)
        #library("Cairo")
        png(filename=picname, width=600, height=600)
        #}
        %>
        Or, upload R script:
        <form action=# id="form1" name="form1" encType="multipart/form-data" method="post" >
            <input type="file" id="file" name="file1"><br>
            <INPUT type="submit" value="Run">
        </form>
        <%
        if(!is.null(FILES$file1)){
        if(!is.null(COOKIES$"N")){
        filename <- COOKIES$"N"
        }else{
        filename <- as.numeric(Sys.time())
        setCookie("N", filename)
        }
        file <- file.path("/tmp",paste(filename, ".R", sep=""))
        file.copy(FILES$file1$tmp_name, file, overwrite=TRUE)
        picname <- paste(filename, ".png", sep="")
        png(filename=picname, width=600, height=600)
        }
        %>
        <h3>Results: (<a href="/images/R/<%=picname%>" target="_blank">Pic</a> if plot)</h3>
        <pre>
          <%
          if(!is.null(file)){
          source(file, echo=TRUE)
          dev.off()
          }
          %>
        </pre>
    </body>
</html>
